package org.fu.crowd;


import com.aliyun.api.gateway.demo.util.HttpUtils;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;

import java.util.HashMap;
import java.util.Map;

public class Test {
    public static void main(String[] args) {
        //短信接口调用的url地址
        String host = "https://gyytz.market.alicloudapi.com";
        // 具体发送短信的地址
        String path = "/sms/smsSend";
        //请求方式
        String method = "POST";
        //在阿里云自己的控制台上可以看见商家给出的appcode
        //  fb3b5f018cc644f7b00a8c61057af058
        String appcode = "fb3b5f018cc644f7b00a8c61057af058";

        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);

        //封装其他参数
        Map<String, String> querys = new HashMap<>();
        //要发送的验证码
        querys.put("mobile", "13232492505");//手机号
        querys.put("param", "**code**:12345,**minute**:5");
        querys.put("smsSignId", "931e4ab6cff2491ca4777fb439743dcc");//短信前缀id,签名Id
        querys.put("templateId", "305b8db49cdb4b18964ffe255188cb20");//短信正文id，模板
        Map<String, String> bodys = new HashMap<>();


        try {
            /**
             * 重要提示如下:
             * HttpUtils请从
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
             * 下载
             *
             * 相应的依赖请参照
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
             */
            HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
            System.out.println(response.toString());
            //获取response的body
            System.out.println(EntityUtils.toString(response.getEntity()));
            EntityUtils.toString(response.getEntity());
            System.out.println();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
